<!--
  * 工时功能
  *
  * @Author:    yjg
  * @Date:      2024-09-09 11:02:13
  * @Copyright  v1.0
-->
<template>
  <a-modal :title="'编辑【姓名:'+form.name+'】'" :width="450"  :open="visibleFlag"  @cancel="onClose" :maskClosable="false" :destroyOnClose="true">
    <a-form ref="formRef" :model="form" :label-col="{ span: 6 }" >
		<!-- <a-form-item label="姓名"  name="overtimeNumber">
		  <a-input  style="width: 100%"  v-model:value="form.name" placeholder="请输入姓名" disabled="true" />
		</a-form-item> -->
		 <a-form-item label="时数"  name="overtimeNumber">
		   <a-input-number  style="width: 100%"  v-model:value="form.overtimeNumber2" placeholder="时数" />
		 </a-form-item>
    </a-form>

    <template #footer>
      <a-space>
		<a-button @click="onClose">取消</a-button>
        <a-button type="primary" @click="onSubmit">同意</a-button>
      </a-space>
    </template>
  </a-modal>
</template>
<script lang="ts" setup>
  import { reactive, ref, nextTick } from 'vue';
  import _ from 'lodash';
  import { message } from 'ant-design-vue';
  import { SmartLoading } from '/@/components/framework/smart-loading';
  import { workingHoursApi } from '/@/api/business/working-hours/working-hours-api';

  // ------------------------ 事件 ------------------------

  const emits = defineEmits(['reloadList']);

  // ------------------------ 显示与隐藏 ------------------------
  // 是否显示
  const visibleFlag = ref(false);

  function show(rowData,overtimeFlag) {
    Object.assign(form, formDefault);
    if (rowData && !_.isEmpty(rowData)) {
      Object.assign(form, rowData);
    }
	form.overtimeFlag = overtimeFlag;
    visibleFlag.value = true;
    nextTick(() => {
      formRef.value.clearValidate();
    });
  }

  function onClose() {
    Object.assign(form, formDefault);
    visibleFlag.value = false;
  }
  

  // ------------------------ 表单 ------------------------

  // 组件ref
  const formRef = ref();

  const formDefault = {
	  //工时ID
	  workingHoursId: undefined,
	  //工时类型（0工时，1加班）
	  overtimeFlag: undefined,
	  name:undefined,
	  overtimeNumber2:undefined,
	  overtimeData:undefined,
  };

  let form = reactive({ ...formDefault });


  // 点击确定
  async function onSubmit() {
	SmartLoading.show();
    try {
      await workingHoursApi.allowUpdate(form);
      message.success('编辑成功');
      emits('reloadList');
      onClose();
    } catch (err) {
      message.error('审批失败，请联系管理员!');
    }finally {
      SmartLoading.hide();
    }
  }

  defineExpose({
    show,
  });
</script>
